//<div id="dview" v-show='posts.length>0'>
//<dpost v-for="p in posts" v-bind:post="p" v-bind:pid="p.id"></dpost>
//</div>

initialize('id', 'key');

Vue.component('dpost', {
  props: ['post'],
  template: '<div class="row w3-border-bottom"><a href="javascript:void(0)"><h2 class="post-title"  onclick="showPost(this)"><p class="w3-hide">{{post.pid}}</p>{{post.title}}</h2></a><div><a href="javascript:void(0)"><div class="post-content-preview" onclick="showPost(this)"><p class="w3-hide">{{post.pid}}</p>{{post.digest}}</div></a><p class="post-meta" style="margin: 10px 0;"> Posted by JunMing on {{post.date}}</p><div class="tags"><a class="w3-aqua w3-hover-light-blue" v-for="tag in post.tags" href="javascript:void(0)" title="{{tag}}">{{tag}}</a></div></div></div>'
})

let dv = new Vue({
   el:'#dview',
   data:{
       posts:[
       ]
   }
});
getPosts();

function showPost(e)
{
   let eid = e.querySelector(".w3-hide");
   if(eid)
   {
    window.location.href += ('dpost/index.html?postid='+eid.innerHTML);

      console.log(eid.innerHTML);       
   }
}

function getPosts()
{
    findItemsEqualTo('NEWPOSTS', 'mode', 1, function(tname,results)
    {
        for(let i=0;i<results.length;i++)
        {
           let pd = {};
           pd.title = results[i].get('title');
           pd.digest= results[i].get('mdcontent').slice(1,100);
           pd.tags = results[i].get('tags');
           pd.link = 'showdpost.html?';
           pd.pid = results[i].id;
           pd.date = '';//convert from createat;
           dv.posts.push(pd);
        }
    },
    function(tname,error)
    {
    }
    )
}